Define description_events_order also as a class method

There are actually two forms of description(), `description do...end`
and `description <<-MD...MD`, and in the former we need an instance
method and in the latter we need a class method to be called.

Akinori MUSHA 9 years ago
parent
commit
d11dec715c
1 changed files with 18 additions and 14 deletions
  1. 18 14
      app/concerns/sortable_events.rb

+ 18 - 14
app/concerns/sortable_events.rb

@@ -5,20 +5,8 @@ module SortableEvents
5 5
     validate :validate_events_order
6 6
   end
7 7
 
8
-  def description_events_order(events = 'events created in each run')
9
-    <<-MD.lstrip
10
-        To specify the order of #{events}, set `events_order` to an array of sort keys, each of which looks like either `expression` or `[expression, type, descending]`, as described as follows:
11
-
12
-        * _expression_ is a Liquid template to generate a string to be used as sort key.
13
-
14
-        * _type_ (optional) is one of `string` (default), `number` and `time`, which specifies how to evaluate _expression_ for comparison.
15
-
16
-        * _descending_ (optional) is a boolean value to determine if comparison should be done in descending (reverse) order, which defaults to `false`.
17
-
18
-        Sort keys listed eariler take precedence over ones listed later.  For example, if you want to sort articles by the date and then by the author, specify `[["{{date}}", "time"], "{{author}}"]`.
19
-
20
-        Sorting is done stably, so even if all events have the same set of sort key values the original order is retained.  Also, a special Liquid variable `_index_` is provided, which contains the zero-based index number of each event, which means you can exactly reverse the order of events by specifying `[["{{_index_}}", "number", true]]`.
21
-    MD
8
+  def description_events_order(*args)
9
+    self.class.description_events_order(*args)
22 10
   end
23 11
 
24 12
   module ClassMethods
@@ -34,6 +22,22 @@ module SortableEvents
34 22
     def cannot_order_created_events?
35 23
       !can_order_created_events?
36 24
     end
25
+
26
+    def description_events_order(events = 'events created in each run')
27
+      <<-MD.lstrip
28
+        To specify the order of #{events}, set `events_order` to an array of sort keys, each of which looks like either `expression` or `[expression, type, descending]`, as described as follows:
29
+
30
+        * _expression_ is a Liquid template to generate a string to be used as sort key.
31
+
32
+        * _type_ (optional) is one of `string` (default), `number` and `time`, which specifies how to evaluate _expression_ for comparison.
33
+
34
+        * _descending_ (optional) is a boolean value to determine if comparison should be done in descending (reverse) order, which defaults to `false`.
35
+
36
+        Sort keys listed eariler take precedence over ones listed later.  For example, if you want to sort articles by the date and then by the author, specify `[["{{date}}", "time"], "{{author}}"]`.
37
+
38
+        Sorting is done stably, so even if all events have the same set of sort key values the original order is retained.  Also, a special Liquid variable `_index_` is provided, which contains the zero-based index number of each event, which means you can exactly reverse the order of events by specifying `[["{{_index_}}", "number", true]]`.
39
+      MD
40
+    end
37 41
   end
38 42
 
39 43
   def can_order_created_events?